package com.soup.faker.wrapper;

import com.soup.faker.api.Generator;

import java.util.*;

/**
 * 复合生成器
 * 生成复合对象，返回 LinkedHashMap
 */
public class ComplexGenerator implements Generator<Map<String, Object>> {
    private Map<String, Generator<?>> propGenerators;

    public ComplexGenerator(Map<String, Generator<?>> propGenerators) {
        Objects.requireNonNull(propGenerators);
        this.propGenerators = propGenerators;
    }

    public Map<String, Object> get() {
        Map<String, Object> result = new LinkedHashMap<>();
        propGenerators.forEach((key, generator) -> {
            result.put(key, propGenerators.getOrDefault(key, NullGenerator.getInstance()).get());
        });
        return result;
    }

}
